﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class ProductManage_Manage_TProductType_PIMInfoManage : System.Web.UI.Page
{
    private TProductType_PIMInfo tppi;
    //private static string productTypeID;

    public ProductManage_Manage_TProductType_PIMInfoManage()
    {
        tppi = new TProductType_PIMInfo();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string productTypeID = this.TextBox1.Text.Trim();
        BindPIMInfo(productTypeID);
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string productTypeID = this.TextBox1.Text.Trim();
        TProductType_PIMInfoInfo tppii = new TProductType_PIMInfoInfo(productTypeID, this.TextBox2.Text.Trim(), this.TextBox3.Text.Trim(), this.TextBox4.Text.Trim(), this.TextBox5.Text.Trim());
        try
        {
            tppi.Insert(tppii);
        }
        catch
        {
            string str = "添加失败，请联系相关人员！";
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
            return;
        }
        string str1 = "添加成功";
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str1 + "');</script>");
        BindPIMInfo(productTypeID);
    }

    private void BindPIMInfo(string productTypeID)
    {
        this.GridView1.DataSource = tppi.GetTProductType_PIMInfobyID(productTypeID);
        this.GridView1.DataBind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                ((LinkButton)e.Row.Cells[5].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除!')");
            }
        }
    }
    
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string productTypeID = this.GridView1.Rows[e.RowIndex].Cells[0].Text.Trim();
        string testItemName = this.GridView1.Rows[e.RowIndex].Cells[1].Text.Trim();
        TPPIMItem item = new TPPIMItem { ProductTypeID = productTypeID, TestItemName = testItemName };
        if (tppi.DeleteItem(item))
        {
            BindPIMInfo(productTypeID);
        }
        else
        {
            string str = "删除失败，请联系相关人员！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
            BindPIMInfo(productTypeID);
        }
    }
}
